package everyday.m20230309;

import java.util.HashSet;
import java.util.Set;

/**
 * leetcode 题2367. 算术三元组的数目
 */
public class Q23230331 {

    public int arithmeticTriplets(int[] nums, int diff) {
        Set<Integer> numSets = new HashSet<>();
        for (int num : nums) {
            numSets.add(num);
        }
        int count = 0;
        for (int i = 0; i < nums.length - 3; i++) {
            if (numSets.contains(nums[i] + diff) && numSets.contains(nums[i] + 2* diff)) {
                count++;
            }
        }
        return count;
    }
}
